package com.ruoyi.quartz.task;

import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ruoyi.system.domain.aggregation.Account;
import com.ruoyi.system.mapper.aggregation.AccountMapper;

/**
 * 账户结算定时任务
 * 每月15日更新可提现金额
 * 
 * @author ruoyi
 * @date 2025-01-01
 */
@Component("accountSettlementTask")
public class AccountSettlementTask
{
    @Autowired
    private AccountMapper accountMapper;

    /**
     * 每月15日更新可提现金额
     * 将总余额转为可提现余额
     */
    public void settleAccounts()
    {
        System.out.println("开始执行账户结算任务...");
        
        try
        {
            // 查询所有账户
            Account query = new Account();
            List<Account> accounts = accountMapper.selectAccountList(query);
            
            for (Account account : accounts)
            {
                // 将总余额转为可提现余额
                if (account.getTotalBalance() > 0)
                {
                    account.setBalance(account.getTotalBalance());
                    account.setUpdateTime(new Date());
                    accountMapper.updateAccount(account);
                }
            }
            
            System.out.println("账户结算任务完成，共处理 " + accounts.size() + " 个账户");
        }
        catch (Exception e)
        {
            System.err.println("账户结算任务执行失败：" + e.getMessage());
            e.printStackTrace();
        }
    }
}

